home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 288_01.zip / TIME.C < prev    next >
Text File  |  1993-04-01  |  2KB  |  47 lines

  1. /*
  2.         HEADER:         CUG000.06;
  3.         TITLE:          GetTime, ElapsedTime;
  4.         DATE:           Mar 89;
  5.         DESCRIPTION:    Samples Clock Counter to Find Elapsed Time;
  6.         VERSION:        2.0;
  7.         FILENAME:       TIME.C;
  8.         SEE-ALSO:       TSP.C, NN.C, POPT.C, 2OPT.C, HYBRID.C, 3OPT.C, FN.C,
  9.                         BOOLEAN.H, NODELIST.H, TSP.H,
  10.                         BLDMTX.C, PRTMTX.C;
  11.         AUTHORS:        Kevin E. Knauss;
  12.         WARNINGS:       Function GetTime is MIX C Compiler Dependent;
  13. */
  14.  
  15. #include <stdlib.h>
  16.  
  17. #define TicksPerHour 65536
  18.  
  19. /** ------------------------------------------------------------------
  20.       This module is designed to establish a beginning time (GetTime)
  21.       and total execution time (ElapsedTime) of a procedure or operation.
  22.       Time is measured in ticks which are fractional portions of a second
  23.       (there are 65536 "TicksPerHour" so one tick is about 55 miliseconds).
  24.     ------------------------------------------------------------------ **/
  25.  
  26. long GetTime()
  27. {
  28.     REGS reg;
  29.  
  30.     reg.byte.ah = 0;
  31.     bios(0x1A, ®);
  32.     return ((long) ((unsigned) reg.word.cx) * TicksPerHour
  33.                                                   + (unsigned) reg.word.dx);
  34. } /* GetTime */
  35.  
  36. long ElapsedTime (TicksBegin)
  37.    long TicksBegin;
  38. {
  39.    long TicksEnd;
  40.  
  41.    TicksEnd = GetTime ();
  42.    if (TicksEnd < TicksBegin) {  /* midnight passed during interval */
  43.       TicksEnd += (24 * TicksPerHour);
  44.    }
  45.    return (TicksEnd - TicksBegin);
  46. } /* ElapsedTime */
  47.